package com.uaniheng.util.matcher;

import java.util.Map;

/**
 * @author HC
 */
class MultiCondition implements Condition {

    /**
     *
     */
    public static final ElementEnum STATUS = ElementEnum.MULTI_CONDITION;

    /**
     * 符合条件的运算符
     * and or
     */
    private final String operator;

    private final Condition first;

    private final Condition second;


    MultiCondition(Condition first, Condition second, String operator){
        this.first = first;
        this.second = second;
        this.operator = operator;
    }

    @Override
    public boolean match(Map<String, String> map) {

     if ("and".equals(operator)){
            return first.match(map) && second.match(map);
        }else if ("or".equals(operator)){
            return first.match(map) || second.match(map);
        }
        return false;
    }

    @Override
    public ElementEnum getStatus() {
        return STATUS;
    }

    MultiCondition and(Condition second){
        return new MultiCondition(first, second, "and");
    }

    MultiCondition or(Condition second){
        return new MultiCondition(first, second, "or");
    }
}
